﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AppDataStruct;
using System.IO;

namespace PrintExcel
{
    public class DataConverter
    {
        private PreApplyInfo _appInfo = new PreApplyInfo();

        private SFZInfo _sfzInfo = new SFZInfo();

        private ExcelData _config = null;

        private Dictionary<string, string> _dicMap = new Dictionary<string, string>();

        string year = DateTime.Now.Year.ToString();
        string month = DateTime.Now.Month.ToString();
        string day = DateTime.Now.Day.ToString();

        public Dictionary<string, string> MapData
        {
            get { return _dicMap; }
        }

        public DataConverter(PreApplyInfo appInfo, SFZInfo sfzInfo, ExcelData config)
        {
            _appInfo = appInfo;
            _sfzInfo = sfzInfo;
            //_sfzInfo.SFZZM = appInfo.SFZZM;
            //_sfzInfo.SFZBM = appInfo.SFZBM;
            _config = config;
        }

        private void DicAddParam(string key, string value)
        {
            LogLib.Log.WriteAsync($"Dic Add,key:[{key}],value:[{value}]");
            _dicMap.Add(key, value);
        }
        private void AddPersonInfo()
        {
            string tbsj = string.Format("填表时间: {0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm"));
            DicAddParam("sqxj", tbsj);
            DicAddParam("jqbh", _config.Printer.DeviceName + _config.Printer.DeviceNo);

            DicAddParam("xm", _appInfo.ZWXM);
            DicAddParam("pyx", _appInfo.YWX);
            DicAddParam("pym", _appInfo.YWM);
            DicAddParam("xb", _appInfo.XB.Value);
            DicAddParam("mz", _appInfo.MZ.Value);
            if (!string.IsNullOrEmpty(_appInfo.CSRQ) && _appInfo.CSRQ.Length == 8)
            {
                string birth = _appInfo.CSRQ.Substring(0, 4) + "-" + _appInfo.CSRQ.Substring(4, 2) + "-" + _appInfo.CSRQ.Substring(6, 2);
                DicAddParam("csrq", birth);
            }
            else
            {
                DicAddParam("csrq", _appInfo.CSRQ);
            }

            DicAddParam("csd", _appInfo.CSD.Value);
            DicAddParam("hkszd", _appInfo.HKSZD.Value);
            DicAddParam("brlxdh", _appInfo.LXDH);
            DicAddParam("jjqklxrxm", _appInfo.JJLXR);
            DicAddParam("jjqklxrdh", _appInfo.JJLXDH);

            DicAddParam("yjdz", _appInfo.YJDZ);
            DicAddParam("yb", _appInfo.YB);
            DicAddParam("sjrxm", _appInfo.SJR);
            DicAddParam("sjrlxdh", _appInfo.SJRLXDH);

            DicAddParam("Time_Year_2", year);
            DicAddParam("Time_Month_2", month);
            DicAddParam("Time_Day_2", day);

            DicAddParam("Time_Year_4", year);
            DicAddParam("Time_Month_4", month);
            DicAddParam("Time_Day_4", day);

            if (_appInfo.ZY.Code == "19" || _appInfo.ZY.Value == "工人")
            {
                DicAddParam("zy_gr_1", "1");
            }
            else if (_appInfo.ZY.Code == "20" || _appInfo.ZY.Value == "农民")
            {
                DicAddParam("zy_nm_1", "1");
            }
            else if (_appInfo.ZY.Code == "33" || _appInfo.ZY.Value == "商人")
            {
                DicAddParam("zy_sr_1", "1");
            }
            else if (_appInfo.ZY.Code == "38" || _appInfo.ZY.Value == "学生")
            {
                DicAddParam("zy_xs_1", "1");
            }
            else if (_appInfo.ZY.Code == "40" || _appInfo.ZY.Value == "公司职员")
            {
                DicAddParam("zy_gszy_1", "1");
            }
            else if (_appInfo.ZY.Code == "44" || _appInfo.ZY.Value == "事业单位工作人员")
            {
                DicAddParam("zy_sydwgzry_1", "1");
            }
            else if (_appInfo.ZY.Code == "42" || _appInfo.ZY.Value == "军人")
            {
                DicAddParam("zy_jr_1", "1");
            }
            else if (_appInfo.ZY.Code == "31" || _appInfo.ZY.Value == "公务员")
            {
                DicAddParam("zy_gwy_1", "1");
            }
            else if (_appInfo.ZY.Code == "45" || _appInfo.ZY.Value == "自由职业者")
            {
                DicAddParam("zy_zyzyz_1", "1");
            }
            else if (_appInfo.ZY.Code == "99" || _appInfo.ZY.Value == "其他人员")
            {
                DicAddParam("zy_qtry_1", "1");
            }

            DicAddParam("Time_Year_6", year);
            DicAddParam("Time_Month_6", month);
            DicAddParam("Time_Day_6", day);
        }

        private void AddOldHZInfo()
        {
            DicAddParam("PassportNoNow", _appInfo.HZSQ.ZJHM);
            DicAddParam("PassportValidity", _appInfo.HZSQ.ZJYXQZ);
        }

        private void AddOldSCZInfo()
        {
            DicAddParam("HKMacaoNoNow", _appInfo.SCZSQ.ZJHM);
            DicAddParam("HKMacaoValidity", _appInfo.SCZSQ.ZJYXQZ);
        }

        private void AddOldDLZInfo()
        {
            DicAddParam("TwNoNow", _appInfo.DLZSQ.ZJHM);
            DicAddParam("TwValidity", _appInfo.DLZSQ.ZJYXQZ);
        }

        /// <summary>
        ///  港澳证探亲亲属信息
        /// </summary>
        private void AddSCZQSInfo()
        {
            DicAddParam("gaqsxm", _appInfo.SCZSQ.QSXM);
            DicAddParam("gaqsxb", _appInfo.SCZSQ.QSXB.Value);
            DicAddParam("gasfzh", _appInfo.SCZSQ.QSSFZH);
            DicAddParam("lxzjhm", _appInfo.SCZSQ.LXZJHM);
            DicAddParam("ysqrgx", _appInfo.SCZSQ.QSGX.Value);

            //DicAddParam("Guardian_Mandatary", "");
            //DicAddParam("Time_Year_1", "");
            //DicAddParam("Time_Month_1", "");
            //DicAddParam("Time_Day_1", "");
            //DicAddParam("Time_Year_2", "");
            //DicAddParam("Time_Month_2", "");
            //DicAddParam("Time_Day_2", "");
            //DicAddParam("SignatureHK_Macao", "");
            //DicAddParam("Time_Year_3", "");
            //DicAddParam("Time_Month_3", "");
            //DicAddParam("Time_Day_3", "");

            //DicAddParam("Time_Year_4", "");
            //DicAddParam("Time_Month_4", "");
            //DicAddParam("Time_Day_4", "");
            //DicAddParam("Time_Year_5", "");
            //DicAddParam("Time_Month_5", "");
            //DicAddParam("Time_Day_5", "");
            //DicAddParam("Time_Year_6", "");
            //DicAddParam("Time_Month_6", "");
            //DicAddParam("Time_Day_6", "");
            //DicAddParam("Time_Year_7", "");
            //DicAddParam("Time_Month_7", "");
            //DicAddParam("Time_Day_7", "");
            //DicAddParam("Time_Year_8", "");
            //DicAddParam("Time_Month_8", "");
            //DicAddParam("Time_Day_8", "");
        }

        /// <summary>
        /// 护照申请信息
        /// </summary>
        private void AddHZSQInfo()
        {
            if (_appInfo.HZSQ != null && !string.IsNullOrEmpty(_appInfo.HZSQ.YWLB.Value)) // && !string.IsNullOrEmpty(_appInfo.HZSQ.YWBH)
            {
                DicAddParam("qwd", _appInfo.HZSQ.QWD.Value);
                DicAddParam("PassportApply_1", "1");
                if (_appInfo.HZSQ.SQSY.Code == "02" || _appInfo.HZSQ.SQSY.Value == "商务")
                {
                    DicAddParam("cjsy_sw_1", "1");
                }
                else if (_appInfo.HZSQ.SQSY.Code == "10" || _appInfo.HZSQ.SQSY.Value == "探亲")
                {
                    DicAddParam("cjsy_tq_1", "1");
                }
                else if (_appInfo.HZSQ.SQSY.Code == "12" || _appInfo.HZSQ.SQSY.Value == "就业")
                {
                    DicAddParam("cjsy_jy_1", "1");
                }
                else if (_appInfo.HZSQ.SQSY.Code == "13" || _appInfo.HZSQ.SQSY.Value == "定居")
                {
                    DicAddParam("cjsy_dj_1", "1");
                }
                else if (_appInfo.HZSQ.SQSY.Code == "18" || _appInfo.HZSQ.SQSY.Value == "学习")
                {
                    DicAddParam("cjsy_xx_1", "1");
                }
                else if (_appInfo.HZSQ.SQSY.Code == "19" || _appInfo.HZSQ.SQSY.Value == "旅行")
                {
                    DicAddParam("cjsy_lx_1", "1");
                }
                else if (_appInfo.HZSQ.SQSY.Code == "99" || _appInfo.HZSQ.SQSY.Value == "其他")
                {
                    DicAddParam("cjsy_qt_1", "1");
                }

                if (_appInfo.HZSQ.YWLB.Code == "11" || _appInfo.HZSQ.YWLB.Value == "首次申领")
                {
                    DicAddParam("PassportType_1_1", "1");
                }
                else if (_appInfo.HZSQ.YWLB.Code == "21" || _appInfo.HZSQ.YWLB.Value == "补发")
                {
                    DicAddParam("PassportType_2_1", "1");
                }
                else if (_appInfo.HZSQ.YWLB.Code == "31" || _appInfo.HZSQ.YWLB.Value == "换发")
                {
                    DicAddParam("PassportType_3_1", "1");
                }
                else if (_appInfo.HZSQ.YWLB.Code == "13" || _appInfo.HZSQ.YWLB.Value == "失效重新申领")
                {
                    DicAddParam("PassportType_4_1", "1");
                }
                if (_appInfo.HZSQ.SFJZ.Code == "1")
                {
                    DicAddParam("PassportType_5_1", "1");
                    List<LabellextApplyInfo> list = _appInfo.HZSQ.HZJZ;
                    foreach (LabellextApplyInfo info in list)
                    {
                        if (info.JZZL.Code == "11")  // 曾用名
                        {
                            DicAddParam("IsRemarkOldName_1", "1");
                            DicAddParam("hz_cym", info.JZNR);
                        }
                        if (info.JZZL.Code == "19") // 姓名加注
                        {
                            DicAddParam("IsRemarkName_1", "1");
                            DicAddParam("hz_jzxm", info.JZNR);
                        }
                        if (info.JZZL.Code == "1A") //曾持护照号码加注
                        {
                            DicAddParam("IsPassportNo_1", "1");
                            DicAddParam("hz_cchzhm", info.JZNR);
                        }
                    }
                }
                //if (!string.IsNullOrEmpty(_appInfo.HZSQ.YWBH))
                //{
                //    if (_appInfo.HZSQ.SFJZ.Code == "1")
                //    {
                //        DicAddParam("PassportType_5_1", "1");
                //    }
                //}
                if(!string.IsNullOrEmpty(_appInfo.HZSQ.YWBH)) 
                    AddOldHZInfo();
            }
        }

        /// <summary>
        /// 港澳证申请信息
        /// </summary>
        private void AddSCZSQInfo()
        {
            if (_appInfo.SCZSQ != null)  // && !string.IsNullOrEmpty(_appInfo.SCZSQ.YWBH)
            {
                if (!string.IsNullOrEmpty(_appInfo.SCZSQ.YWLB.Value))
                {
                    if (!_dicMap.ContainsKey("HKMacaoApply_1"))
                        DicAddParam("HKMacaoApply_1", "1");
                    DicAddParam("HKMacaoSQTXZ_1", "1");
                    if (_appInfo.SCZSQ.YWLB.Code == "11" || _appInfo.SCZSQ.YWLB.Value == "首次申领")
                    {
                        DicAddParam("HKMacaoYWLB_1", "1");
                    }
                    else if (_appInfo.SCZSQ.YWLB.Code == "21" || _appInfo.SCZSQ.YWLB.Value == "补发")
                    {
                        DicAddParam("HKMacaoYWLB_2", "1");
                    }
                    else if (_appInfo.SCZSQ.YWLB.Code == "31" || _appInfo.SCZSQ.YWLB.Value == "换发")
                    {
                        DicAddParam("HKMacaoYWLB_3", "1");
                    }
                    else if (_appInfo.SCZSQ.YWLB.Code == "13" || _appInfo.SCZSQ.YWLB.Value == "失效重新申领")
                    {
                        DicAddParam("HKMacaoYWLB_4", "1");
                    }

                    DicAddParam("Time_Year_3", year);
                    DicAddParam("Time_Month_3", month);
                    DicAddParam("Time_Day_3", day);
                }

                //else if (_appInfo.SCZSQ.YWLB.Code == "91" || _appInfo.SCZSQ.YWLB.Value == "申请签注")
                //{
                //    DicAddParam("PassportType_5_1", "1");
                //}

                //DicAddParam("HK_MacroCheckImage", _appInfo.HZSQ.SXQM);
                if (!string.IsNullOrEmpty(_appInfo.SCZSQ.YWBH))
                    AddOldSCZInfo();
            }
            
        }

        /// <summary>
        /// 港澳证签注信息
        /// </summary>
        private void AddSCZQZInfo()
        {
            if (_appInfo.SCZSQ.SCZQZ == null || _appInfo.SCZSQ.SCZQZ.Count == 0)
            {
                return;
            }
            if (!_dicMap.ContainsKey("HKMacaoApply_1"))
                DicAddParam("HKMacaoApply_1", "1");
            DicAddParam("HKMacaoSQQZ_1", "1");
            for (int i = 0; i < _appInfo.SCZSQ.SCZQZ.Count; i++)
            {
                LabelApplyInfo info = _appInfo.SCZSQ.SCZQZ[i];
                if (info.QZZL.Code == "1B" || info.QZZL.Value == "个人旅游")
                {
                    TryAdd("HKMacaoRemark_2_1", "1");
                    AddXG_QZ_GR(info);
                    AddAM_QZ_GR(info);
                }
                else if (info.QZZL.Code == "12" || info.QZZL.Value == "团队旅游")
                {
                    TryAdd("HKMacaoRemark_1_1", "1");
                    AddXG_QZ_TD(info);
                    AddAM_QZ_TD(info);
                }
                else if (info.QZZL.Code == "13" || info.QZZL.Value == "商务")
                {
                    TryAdd("HKMacaoRemark_3_1", "1");
                    AddXG_QZ_SW(info);
                    AddAM_QZ_SW(info);
                }
                else if (info.QZZL.Code == "11" || info.QZZL.Value == "探亲")
                {
                    TryAdd("HKMacaoRemark_4_1", "1");
                    AddXG_QZ_TQ(info);
                    AddAM_QZ_TQ(info);
                }
                else if (info.QZZL.Code == "19" || info.QZZL.Value == "其他")
                {
                    TryAdd("HKMacaoRemark_5_1", "1");
                    AddXG_QZ_QT(info);
                    AddAM_QZ_QT(info);
                }
                else if (info.QZZL.Code == "1G" || info.QZZL.Value == "逗留")
                {
                    TryAdd("HKMacaoRemark_6_1", "1");
                }
            }
        }

        private void AddXG_QZ_GR(LabelApplyInfo info)
        {
            if (info.QWD.Code == "HKG" || info.QWD.Value == "香港")
            {
                if (info.YXQX.Code == "Y03" && info.YXCS.Code == "1")
                {
                    TryAdd("HKTime_GR_1", "1");
                }
                if (info.YXQX.Code == "Y03" && info.YXCS.Code == "2")
                {
                    TryAdd("HKTime_GR_2", "1");
                }
                if (info.YXQX.Code == "N01" && info.YXCS.Code == "1")
                {
                    TryAdd("HKTime_GR_7", "1");
                }
                if (info.YXQX.Code == "N01" && info.YXCS.Code == "2")
                {
                    TryAdd("HKTime_GR_8", "1");
                }
            }
        }

        private void AddXG_QZ_TD(LabelApplyInfo info)
        {
            if (info.QWD.Code == "HKG" || info.QWD.Value == "香港")
            {
                if (info.YXQX.Code == "Y03" && info.YXCS.Code == "1")
                {
                    TryAdd("HKTime_TD_1", "1");
                }
                if (info.YXQX.Code == "Y03" && info.YXCS.Code == "2")
                {
                    TryAdd("HKTime_TD_2", "1");
                }
                if (info.YXQX.Code == "N01" && info.YXCS.Code == "1")
                {
                    TryAdd("HKTime_TD_7", "1");
                }
                if (info.YXQX.Code == "N01" && info.YXCS.Code == "2")
                {
                    TryAdd("HKTime_TD_8", "1");
                }
            }
        }

        private void AddAM_QZ_GR(LabelApplyInfo info)
        {
            if (info.QWD.Code == "MAC" || info.QWD.Value == "澳门")
            {
                if (info.YXQX.Code == "Y03" && info.YXCS.Code == "1")
                {
                    TryAdd("MacaoTime_GR_1", "1");
                }
                if (info.YXQX.Code == "N01" && info.YXCS.Code == "1")
                {
                    TryAdd("MacaoTime_GR_7", "1");
                }
            }
        }

        private void AddAM_QZ_TD(LabelApplyInfo info)
        {
            if (info.QWD.Code == "MAC" || info.QWD.Value == "澳门")
            {
                if (info.YXQX.Code == "N01" && info.YXCS.Code == "1")
                {
                    TryAdd("MacaoTime_TD_7", "1");
                }
                if (info.YXQX.Code == "Y03" && info.YXCS.Code == "1")
                {
                    TryAdd("MacaoTime_TD_1", "1");
                }
            }
        }

        private void AddXG_QZ_SW(LabelApplyInfo info)
        {
            if (info.QWD.Code == "HKG" || info.QWD.Value == "香港")
            {
                if (info.YXQX.Code == "Y03" && info.YXCS.Code == "1")
                {
                    TryAdd("HKTime_SW_1", "1");
                }
                if (info.YXQX.Code == "Y03" && info.YXCS.Code == "9")
                {
                    TryAdd("HKTime_SW_3", "1");
                }
                if (info.YXQX.Code == "N01" && info.YXCS.Code == "9")
                {
                    TryAdd("HKTime_SW_9", "1");
                }
            }
        }

        private void AddAM_QZ_SW(LabelApplyInfo info)
        {
            if (info.QWD.Code == "MAC" || info.QWD.Value == "澳门")
            {
                if (info.YXQX.Code == "Y03" && info.YXCS.Code == "1")
                {
                    TryAdd("MacaoTime_SW_1", "1");
                }
                if (info.YXQX.Code == "Y03" && info.YXCS.Code == "9")
                {
                    TryAdd("MacaoTime_SW_3", "1");
                }
                if (info.YXQX.Code == "N01" && info.YXCS.Code == "9")
                {
                    TryAdd("MacaoTime_SW_9", "1");
                }
            }
        }

        /// <summary>
        /// 香港探亲
        /// </summary>
        /// <param name="info"></param>
        private void AddXG_QZ_TQ(LabelApplyInfo info)
        {
            if (info.QWD.Code == "HKG" || info.QWD.Value == "香港")
            {
                if (info.YXQX.Code == "Y03" && info.YXCS.Code == "1")
                {
                    TryAdd("HKTime_TQ_1", "1");
                }
                if (info.YXQX.Code == "Y03" && info.YXCS.Code == "9")
                {
                    TryAdd("HKTime_TQ_3", "1");
                }
                if (info.YXQX.Code == "N01" && info.YXCS.Code == "9")
                {
                    TryAdd("HKTime_TQ_9", "1");
                }
            }
        }

        /// <summary>
        /// 澳门探亲
        /// </summary>
        /// <param name="info"></param>
        private void AddAM_QZ_TQ(LabelApplyInfo info)
        {
            if (info.QWD.Code == "MAC" || info.QWD.Value == "澳门")
            {
                if (info.YXQX.Code == "Y03" && info.YXCS.Code == "1")
                {
                    TryAdd("MacaoTime_TQ_1", "1");
                }
                if (info.YXQX.Code == "Y03" && info.YXCS.Code == "9")
                {
                    TryAdd("MacaoTime_TQ_3", "1");
                }
                if (info.YXQX.Code == "N01" && info.YXCS.Code == "9")
                {
                    TryAdd("MacaoTime_TQ_9", "1");
                }
            }
        }

        /// <summary>
        /// 香港其他
        /// </summary>
        /// <param name="info"></param>
        private void AddXG_QZ_QT(LabelApplyInfo info)
        {
            if (info.QWD.Code == "HKG" || info.QWD.Value == "香港")
            {
                if (info.YXQX.Code == "Y03" && info.YXCS.Code == "1")
                {
                    TryAdd("HKTime_QT_1", "1");
                }
                if (info.YXQX.Code == "Y03" && info.YXCS.Code == "2")
                {
                    TryAdd("HKTime_QT_2", "1");
                }
                if (info.YXQX.Code == "Y03" && info.YXCS.Code == "9")
                {
                    TryAdd("HKTime_QT_3", "1");
                }
            }
        }

        /// <summary>
        /// 澳门其他
        /// </summary>
        /// <param name="info"></param>
        private void AddAM_QZ_QT(LabelApplyInfo info)
        {
            if (info.QWD.Code == "MAC" || info.QWD.Value == "澳门")
            {
                if (info.YXQX.Code == "Y03" && info.YXCS.Code == "1")
                {
                    TryAdd("MacaoTime_QT_1", "1");
                }
                if (info.YXQX.Code == "Y03" && info.YXCS.Code == "2")
                {
                    TryAdd("MacaoTime_QT_2", "1");
                }
                if (info.YXQX.Code == "Y03" && info.YXCS.Code == "9")
                {
                    TryAdd("MacaoTime_QT_3", "1");
                }
            }
        }

        /// <summary>
        /// 台湾证申请信息
        /// </summary>
        private void AddTWZSQInfo()
        {
            if (_appInfo.DLZSQ != null && !string.IsNullOrEmpty(_appInfo.DLZSQ.YWLB.Value)) // && !string.IsNullOrEmpty(_appInfo.DLZSQ.YWBH)
            {
                if (!_dicMap.ContainsKey("TaiWanApply_1"))
                    DicAddParam("TaiWanApply_1", "1");
                DicAddParam("TaiWanSQTXZ_1", "1");
                if (_appInfo.DLZSQ.YWLB.Code == "11" || _appInfo.DLZSQ.YWLB.Value == "首次申领")
                {
                    DicAddParam("TaiWanYWLB_1", "1");
                }
                else if (_appInfo.DLZSQ.YWLB.Code == "21" || _appInfo.DLZSQ.YWLB.Value == "补发")
                {
                    DicAddParam("TaiWanYWLB_2", "1");
                }
                else if (_appInfo.DLZSQ.YWLB.Code == "31" || _appInfo.DLZSQ.YWLB.Value == "换发")
                {
                    DicAddParam("TaiWanYWLB_3", "1");
                }
                else if (_appInfo.DLZSQ.YWLB.Code == "13" || _appInfo.DLZSQ.YWLB.Value == "失效重新申领")
                {
                    DicAddParam("TaiWanYWLB_4", "1");
                }
                //else if (_appInfo.SCZSQ.YWLB.Code == "91" || _appInfo.SCZSQ.YWLB.Value == "申请签注")
                //{
                //    DicAddParam("PassportType_5_1", "1");
                //}

                if (!string.IsNullOrEmpty(_appInfo.DLZSQ.YWBH))
                    AddOldDLZInfo();
            }
        }

        /// <summary>
        /// 大陆证签注信息
        /// </summary>
        private void AddTWZQZInfo()
        {
            if (_appInfo.DLZSQ.SFQZ.Code == "1" || _appInfo.DLZSQ.SFQZ.Value == "是")
            {
                if (!_dicMap.ContainsKey("TaiWanApply_1"))
                    DicAddParam("TaiWanApply_1", "1");
                DicAddParam("TaiWanSQQZ_1", "1");
                if (_appInfo.DLZSQ.QZZL.Code == "25" || _appInfo.DLZSQ.QZZL.Value == "团队旅游")
                {
                    DicAddParam("TaiWanRemark_1", "1");
                    AddTW_QZ_TD();
                }
                if (_appInfo.DLZSQ.QZZL.Code == "21" || _appInfo.DLZSQ.QZZL.Value == "探亲")
                {
                    DicAddParam("TaiWanRemark_2", "1");
                    AddTW_QZ_TQ();
                }
                if (_appInfo.DLZSQ.QZZL.Code == "27" || _appInfo.DLZSQ.QZZL.Value == "商务")
                {
                    DicAddParam("TaiWanRemark_3", "1");
                    AddTW_QZ_JM();
                }
                if (_appInfo.DLZSQ.QZZL.Code == "22" || _appInfo.DLZSQ.QZZL.Value == "应邀")
                {
                    DicAddParam("TaiWanRemark_4", "1");
                    AddTW_QZ_YY();
                }
                if (_appInfo.DLZSQ.QZZL.Code == "2B" || _appInfo.DLZSQ.QZZL.Value == "个人旅游")
                {
                    DicAddParam("TaiWanRemark_5", "1");
                }
                if (_appInfo.DLZSQ.QZZL.Code == "23" || _appInfo.DLZSQ.QZZL.Value == "定居")
                {
                    DicAddParam("TaiWanRemark_6", "1");
                }
                if (_appInfo.DLZSQ.QZZL.Code == "2A" || _appInfo.DLZSQ.QZZL.Value == "学习")
                {
                    DicAddParam("TaiWanRemark_7", "1");
                }
                if (_appInfo.DLZSQ.QZZL.Code == "26" || _appInfo.DLZSQ.QZZL.Value == "乘务")
                {
                    DicAddParam("TaiWanRemark_8", "1");
                }
                if (_appInfo.DLZSQ.QZZL.Code == "29" || _appInfo.DLZSQ.QZZL.Value == "其他")
                {
                    DicAddParam("TaiWanRemark_9", "1");
                }
                //if (_appInfo.DLZSQ.QZZL.Code == "29" || _appInfo.DLZSQ.QZZL.Value == "其他")
                //{
                //    DicAddParam("TaiWanRemark_10", "1");
                //}
            }
        }

        /// <summary>
        /// 台湾签注：团队旅游
        /// </summary>
        private void AddTW_QZ_TD()
        {
            if (_appInfo.DLZSQ.YXQX.Code == "Y06" && _appInfo.DLZSQ.YXCS.Code == "1")
            {
                DicAddParam("TaiWanTime_TD_1", "1");
            }
            else if (_appInfo.DLZSQ.YXQX.Code == "N01" && _appInfo.DLZSQ.YXCS.Code == "9")
            {
                DicAddParam("TaiWanTime_TD_10", "1");
            }
        }

        /// <summary>
        /// 台湾签注：经贸交流
        /// </summary>
        private void AddTW_QZ_JM()
        {
            if (_appInfo.DLZSQ.YXQX.Code == "Y06" && _appInfo.DLZSQ.YXCS.Code == "1")
            {
                DicAddParam("TaiWanTime_JM_4", "1");
            }
            else if (_appInfo.DLZSQ.YXQX.Code == "N01" && _appInfo.DLZSQ.YXCS.Code == "9")
            {
                DicAddParam("TaiWanTime_JM_10", "1");
            }
        }

        /// <summary>
        /// 台湾签注：应邀
        /// </summary>
        private void AddTW_QZ_YY()
        {
            if (_appInfo.DLZSQ.YXQX.Code == "Y06" && _appInfo.DLZSQ.YXCS.Code == "1")
            {
                DicAddParam("TaiWanTime_YY_4", "1");
            }
            else if (_appInfo.DLZSQ.YXQX.Code == "N01" && _appInfo.DLZSQ.YXCS.Code == "9")
            {
                DicAddParam("TaiWanTime_YY_10", "1");
            }
        }

        /// <summary>
        /// 台湾签注：探亲
        /// </summary>
        private void AddTW_QZ_TQ()
        {
            if (_appInfo.DLZSQ.YXQX.Code == "Y06" && _appInfo.DLZSQ.YXCS.Code == "1")
            {
                DicAddParam("TaiWanTime_TQ_4", "1");
            }
            else if (_appInfo.DLZSQ.YXQX.Code == "N01" && _appInfo.DLZSQ.YXCS.Code == "9")
            {
                DicAddParam("TaiWanTime_TQ_10", "1");
            }
        }

        /// <summary>
        /// 取证方式
        /// </summary>
        private void AddQZFS()
        {
            //if (!string.IsNullOrEmpty(_appInfo.YJDZ))
            if (_appInfo.QZFS.Code == "02")
            {
                DicAddParam("TakeDoc_2", "1");
            }
            else if (_appInfo.QZFS.Code == "01")
            {
                DicAddParam("TakeDoc_1", "1");
            }
        }

        private void AddPicture()
        {
            if (File.Exists(_appInfo.ZZZPPATH))
            {
                DicAddParam("zzzp", _appInfo.ZZZPPATH);
            }
            else if (File.Exists(_sfzInfo.HeaderPicturePath))
            {
                DicAddParam("zzzp", _sfzInfo.HeaderPicturePath);
                LogLib.Log.WriteAsync("制证照片为空，使用身份证照片");
            }
            if (_appInfo.HZSQ != null && File.Exists(_appInfo.HZSQ.SXQM))  //&& !string.IsNullOrEmpty(_appInfo.HZSQ.YWBH)  //没有业务编号也打印手写签名
            {
                DicAddParam("sxqm", _appInfo.HZSQ.SXQM);
            }
            DicAddParam("sfzzm", _appInfo.SFZZM);
            DicAddParam("sfzbm", _appInfo.SFZBM);
        }

        private void AddBarcode()
        {
            if (_appInfo.HZSQ != null && !string.IsNullOrEmpty(_appInfo.HZSQ.YWBH))
            {
                DicAddParam("hz_ywbh_bar", _appInfo.HZSQ.YWBH);
                DicAddParam("hz_ywbh", _appInfo.HZSQ.YWBH);
            }
            if (_appInfo.SCZSQ != null && !string.IsNullOrEmpty(_appInfo.SCZSQ.YWBH))
            {
                DicAddParam("scz_ywbh_bar", _appInfo.SCZSQ.YWBH);
                DicAddParam("scz_ywbh", _appInfo.SCZSQ.YWBH);
            }
            if (_appInfo.DLZSQ != null && !string.IsNullOrEmpty(_appInfo.DLZSQ.YWBH))
            {
                DicAddParam("dlz_ywbh_bar", _appInfo.DLZSQ.YWBH);
                DicAddParam("dlz_ywbh", _appInfo.DLZSQ.YWBH);
            }
            if (!string.IsNullOrEmpty(_appInfo.ZZZPPATH))
            {
                DicAddParam("zzzpath_bar", _appInfo.ZZZPPATH);
                DicAddParam("zzzpath", _appInfo.ZZZPPATH);
            }
        }

        private void GetFingerInfo(string wsqFileName)
        {
            //222222222233333-1111-5A-EEA001-17-100-096-0.WSQ
            string[] fingerInfo = wsqFileName.Split('-');
            if (fingerInfo.Length == 8)
            {
                string fingerPos = fingerInfo[2];//指位信息
                foreach (var item in fingerPos)
                {
                    _dicMap.Add(string.Format("Hand_{0}_1", item), "1");
                }

                //指纹相关签名
                if (_appInfo.HZSQ != null && !string.IsNullOrEmpty(_appInfo.HZSQ.YWBH) && File.Exists(_appInfo.HZSQ.SXQM))
                {

                    DicAddParam("FingerCollectImage", _appInfo.HZSQ.SXQM);


                    //DicAddParam("Time_Year_4", year);
                    //DicAddParam("Time_Month_4", month);
                    //DicAddParam("Time_Day_4", day);
                }
            }
        }

        private void AddFingerInfo()
        {
            if (!string.IsNullOrEmpty(_appInfo.HZSQ.WSQ_File))
            {
                GetFingerInfo(_appInfo.HZSQ.WSQ_File);
            }
            else if (!string.IsNullOrEmpty(_appInfo.SCZSQ.WSQ_File))
            {
                GetFingerInfo(_appInfo.SCZSQ.WSQ_File);
            }
            else if (!string.IsNullOrEmpty(_appInfo.DLZSQ.WSQ_File))
            {
                GetFingerInfo(_appInfo.DLZSQ.WSQ_File);
            }
        }

        public void Excute()
        {
            AddPersonInfo();
            AddQZFS();
            AddHZSQInfo();
            AddSCZSQInfo();
            AddSCZQSInfo();
            AddSCZQZInfo();
            AddTWZSQInfo();
            AddTWZQZInfo();
            AddPicture();
            AddBarcode();
            AddFingerInfo();
        }

        private void TryAdd(string key, string value)
        {
            if (!_dicMap.ContainsKey(key))
            {
                _dicMap.Add(key, value);
            }
        }
    }
}
